package com.guoxin.concurrentprogramming.chapter4.producerconsumer.disruptor;
/*
import com.lmax.disruptor.BlockingWaitStrategy;
import com.lmax.disruptor.RingBuffer;
import com.lmax.disruptor.dsl.Disruptor;
import com.lmax.disruptor.dsl.ProducerType;

import java.nio.ByteBuffer;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;

public class Main {
    public static void main(String[] args) throws InterruptedException {
        PCDataFactory factory = new PCDataFactory();
        ExecutorService service = Executors.newCachedThreadPool();
        int bufferSize = 1024;
        ThreadFactory factory1 = r -> new Thread(r, "T");
        Disruptor<PCData> disruptor = new Disruptor<PCData>(
                factory, bufferSize,service, ProducerType.MULTI, new BlockingWaitStrategy());

        disruptor.handleEventsWithWorkerPool(new Consumer(), new Consumer(), new Consumer(), new Consumer(), new Consumer());
        disruptor.start();
        RingBuffer<PCData> ringBuffer = disruptor.getRingBuffer();
        Producer p = new Producer(ringBuffer);

        ByteBuffer bb = ByteBuffer.allocate(8);
        for (long i = 0; true; i++) {
            bb.putLong(0, i);
            p.pushData(bb);
            Thread.sleep(100);
            System.out.println("add data " + i);
        }
    }
}*/
